package model

import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.widgets.Button
import org.uqbar.commons.utils.Observable
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.actions.MessageSend
import org.uqbar.arena.windows.Dialog

@Observable
class EditorCaraceristicas<T> extends Dialog<T> {
		@Property String propiedad
		@Property String elemAgregar
		@Property String elemEliminar
		@Property String agregar //MethodName
		@Property String eliminar
	new(WindowOwner owner, T model, String propiedad,String elemAgregar,String  elemEliminar, String  agregar, String eliminar) {
		super(owner, model)
		this._propiedad = propiedad
		this._elemAgregar = elemAgregar
		this._elemEliminar =  elemEliminar
		this._agregar = agregar
		this._eliminar = eliminar

	}

	override protected createFormPanel(Panel mainPanel) {
		
		this.setTitle("Editar Caracteristicas")

		new Label(mainPanel).setText("Caracteristicas")

		new List(mainPanel) => [
			bindItemsToProperty(this.propiedad)
			bindValueToProperty(this.elemEliminar)
				width = 200
			    heigth = 50
		]
		new Button(mainPanel) => [
			caption = "eliminar"
			onClick = [ |
				(new MessageSend(this.modelObject, this.eliminar)).execute
				close
			]
		]
		new TextBox(mainPanel) => [
			bindValueToProperty(this.elemAgregar)
		]

		new Button(mainPanel) => [
			caption = "agregar"
			onClick = new MessageSend(this.modelObject, this.agregar)
		]
		
	}

	override protected addActions(Panel actionsPanel) {
		new Button(actionsPanel) => [
			caption = "aceptar"
			onClick[ |
				close
			]
		]
	}

}
